package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.HotelForm;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.IHotelFormService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("hotelForms")
public class HotelFormController {
    @Autowired
    private IHotelFormService formService;
    @Autowired
    private IUserService userService;

    @PostMapping
    public JsonResult save(HotelForm hotelForm){
        User user = UserContext.getCurrentUser();
        JsonResult result = new JsonResult();
        try {
            formService.save(hotelForm,user);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @GetMapping("/{userId}/getHotelForm")
    public JsonResult getHotelForm(@PathVariable Long userId){
        List<HotelForm> list = formService.getHotelForm(userId);
        return new JsonResult().setResult(list);
    }
}
